﻿using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows;

namespace FEZCommunicationSimulation
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private const string dottedServerIPAddress = "192.168.153.108";
        private const int port = 2000;

        public MainWindow()
        {
            InitializeComponent();

            using (Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                // Addressing
                IPHostEntry entry = Dns.GetHostEntry(dottedServerIPAddress);
                IPAddress ipAddress = entry.AddressList[0];
                IPEndPoint serverEndPoint = new IPEndPoint(ipAddress, port);
                
                // Connecting
                Debug.Print("Connecting to server " + serverEndPoint + ".");
                clientSocket.Connect(serverEndPoint);
                Debug.Print("Connected to server.");
                
                // Sending
                byte[] messageBytes = Encoding.UTF8.GetBytes("Hello World!");
                clientSocket.Send(messageBytes);
            }// the socket will be closed here
        }
    }
}
